//
//	File Name   :	Dx10VertexBuffer.cpp
//	Description :	Dx10VertexBuffer implementation file.
//	Author		:	William McVicar
//  Mail		:	mcvicar.william@gmail.com
//

//  Precompiled Header
#include "CommonDefines.h"
#ifdef DX10

//  Library Includes

//  Local Includes
#include "ProteinFramework.h"
#include "IRenderer.h"
#include "RendererData.h"
#include "VertexBuffer.h"

//  This includes
#include "Dx10VertexBuffer.h"

//	Macros

//  Static Variables

//  Static Function Prototypes

//  Implementation

namespace Protein
{

VertexBuffer::VertexBuffer( const VertexBufferBase* _pVbuffer )
: m_uiVertexSize( _pVbuffer->ElementSize() )
{
	D3D10_BUFFER_DESC bd;
	bd.Usage = D3D10_USAGE_DEFAULT;
	bd.ByteWidth = _pVbuffer->ElementSize() * _pVbuffer->NumElements();
	bd.CPUAccessFlags = 0;
	bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	bd.MiscFlags = 0;

	D3D10_SUBRESOURCE_DATA InitData = {0};
	InitData.pSysMem = _pVbuffer->Data();
	HRESULT hr = Protein::renderer().GetRendererData()->m_pDevice->CreateBuffer( &bd, &InitData, &m_pVertexBuffer );
	PROTEIN_UNUSED( hr );
}

VertexBuffer::~VertexBuffer()
{
	if( m_pVertexBuffer )
	{
		m_pVertexBuffer->Release();
		m_pVertexBuffer = NULL;
	}
}

void VertexBuffer::Enable()
{
	UINT strides[1] = { m_uiVertexSize };
	UINT offsets[1] = {0};
	ID3D10Buffer* pBuffers[1] = { m_pVertexBuffer };
	renderer().GetRendererData()->m_pDevice->IASetVertexBuffers( 0, 1, pBuffers, strides, offsets );
}

}

#endif